package cn.dslcode.security.common;

import org.springframework.security.core.Authentication;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author dongsilin
 * @version 2018/4/4.
 */
public class DataCenter {


    public static final String loginFormUri = "/authentication/require";
    public static final String logoutUri = "/authentication/signout";
    public static final String accessDenyUri = "/error/deny";

    public static final Map<String, Authentication> authenticationMap = new HashMap<>();

    public static final Set<Authority> auths = new HashSet<Authority>() {
        {
            add(new Authority(1, "查看用户", "USER_VIEW"));
            add(new Authority(2, "修改用户", "USER_EDIT"));
        }
    };

    public static final Set<Role> roles = new HashSet<Role>() {
        {
            // 必须加 ROLE_ ，用于 @PreAuthorize("hasRole('ROLE_xxx')")
            add(new Role(1, "管理员", "ROLE_ADMIN", auths));
            add(new Role(2, "用户", "ROLE_USER", auths.stream().filter(a -> a.getId().equals(1)).collect(Collectors.toSet())));
        }
    };

    public static final Set<SystemUser> users = new HashSet<SystemUser>() {
        {
            SystemUser admin = new SystemUser(1, "admin", "$2a$08$HYbg9ejXsLzw5NBrZRjIUuTzmtAcJu0S9WIIZsmgLtL1QL0Uryx92", true);
            admin.setRoles(roles);
            add(admin);
            SystemUser user = new SystemUser(2, "user", "$2a$08$HYbg9ejXsLzw5NBrZRjIUuTzmtAcJu0S9WIIZsmgLtL1QL0Uryx92", true);
            user.setRoles(roles.stream().filter(a -> a.getId().equals(2)).collect(Collectors.toSet()));
            add(user);
        }
    };

}
